<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加物品 - 归物</title>

    <!-- 网站图标 -->
    <link rel="icon" type="image/png" href="/icon.png">
    <link rel="shortcut icon" type="image/png" href="/icon.png">
    <link rel="apple-touch-icon" href="/icon.png">

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }

        .container-fluid {
            padding: 20px;
            max-width: 400px;
            margin: 0 auto;
        }

        /* 顶部标题栏 */
        .header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 24px;
            color: white;
        }

        .header h1 {
            font-size: 20px;
            font-weight: 600;
            margin: 0;
        }

        .back-btn {
            color: white;
            font-size: 18px;
            text-decoration: none;
            padding: 8px;
        }

        /* 表单卡片 */
        .form-card {
            background: white;
            border-radius: 20px;
            padding: 24px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            font-size: 14px;
            font-weight: 600;
            color: #374151;
            margin-bottom: 8px;
            display: block;
        }

        .form-control {
            width: 100%;
            padding: 16px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            background: #f9fafb;
            transition: all 0.2s ease;
        }

        .form-control:focus {
            outline: none;
            border-color: #4285f4;
            background: white;
            box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
        }

        .form-select {
            appearance: none;
            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
            background-position: right 12px center;
            background-repeat: no-repeat;
            background-size: 16px;
            padding-right: 40px;
        }

        .btn-primary {
            width: 100%;
            background: linear-gradient(135deg, #4285f4 0%, #6366f1 100%);
            border: none;
            border-radius: 12px;
            padding: 16px;
            font-size: 16px;
            font-weight: 600;
            color: white;
            transition: all 0.2s ease;
            margin-top: 20px;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(66, 133, 244, 0.3);
        }

        /* 底部导航 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 100%;
            max-width: 400px;
            background: white;
            padding: 12px 0;
            border-top: 1px solid #e5e7eb;
            display: flex;
            justify-content: space-around;
        }

        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #6b7280;
            text-decoration: none;
            font-size: 12px;
        }

        .nav-item.active {
            color: #4285f4;
        }

        .nav-item i {
            font-size: 20px;
            margin-bottom: 4px;
        }

        .main-content {
            padding-bottom: 80px;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <!-- 顶部标题栏 -->
        <div class="header">
            <a href="/dashboard" class="back-btn">
                <i class="fas fa-arrow-left"></i>
            </a>
            <h1>添加物品</h1>
            <div style="width: 32px;"></div> <!-- 占位符保持居中 -->
        </div>

        <!-- 表单卡片 -->
        <div class="form-card">
            <!-- 错误消息 -->
            <div th:if="${error}" style="background: #fee2e2; color: #dc2626; padding: 12px; border-radius: 8px; margin-bottom: 20px; font-size: 14px;">
                <i class="fas fa-exclamation-triangle"></i>
                <span th:text="${error}">错误信息</span>
            </div>

            <form th:action="@{/item/add}" th:object="${itemDto}" method="post">
                <div class="form-group">
                    <label for="name" class="form-label">物品名称</label>
                    <input type="text" class="form-control" id="name" th:field="*{name}"
                           placeholder="请输入物品名称" required>
                    <div th:if="${#fields.hasErrors('name')}" style="color: #dc2626; font-size: 12px; margin-top: 4px;">
                        <span th:errors="*{name}">名称错误</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="categoryId" class="form-label">分类</label>
                    <select class="form-control form-select" id="categoryId" name="categoryId" required>
                        <option value="">请选择分类</option>
                        <option value="1">电子产品</option>
                        <option value="2">家具</option>
                        <option value="3">服装</option>
                        <option value="4">书籍</option>
                        <option value="5">运动器材</option>
                        <option value="6">厨具</option>
                        <option value="7">数码配件</option>
                    </select>
                    <div th:if="${#fields.hasErrors('categoryId')}" style="color: #dc2626; font-size: 12px; margin-top: 4px;">
                        <span th:errors="*{categoryId}">分类错误</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="price" class="form-label">价格 (¥)</label>
                    <input type="number" class="form-control" id="price" th:field="*{price}"
                           placeholder="请输入价格" step="0.01" min="0" required>
                    <div th:if="${#fields.hasErrors('price')}" style="color: #dc2626; font-size: 12px; margin-top: 4px;">
                        <span th:errors="*{price}">价格错误</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="purchaseDate" class="form-label">入手时间</label>
                           th:max="${#temporals.format(#temporals.createToday(), 'yyyy-MM-dd')}" required>
                    <div th:if="${#fields.hasErrors('purchaseDate')}" style="color: #dc2626; font-size: 12px; margin-top: 4px;">
                        <span th:errors="*{purchaseDate}">日期错误</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="description" class="form-label">描述 (可选)</label>
                    <textarea class="form-control" id="description" th:field="*{description}"
                              rows="3" placeholder="请输入物品描述"></textarea>
                    <div th:if="${#fields.hasErrors('description')}" style="color: #dc2626; font-size: 12px; margin-top: 4px;">
                        <span th:errors="*{description}">描述错误</span>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save"></i> 保存物品
                </button>
            </form>
        </div>
    </div>

    <!-- 底部导航栏 -->
    <div class="bottom-nav">
        <a href="/dashboard" class="nav-item">
            <i class="fas fa-chart-line"></i>
            <span>资产</span>
        </a>
        <a href="/item/add" class="nav-item active">
            <i class="fas fa-plus"></i>
            <span>添加</span>
        </a>
        <a href="/profile" class="nav-item">
            <i class="fas fa-user"></i>
            <span>我的</span>
        </a>
    </div>

    <script>
        // 设置默认日期为今天
        document.addEventListener('DOMContentLoaded', function() {
            const today = new Date().toISOString().split('T')[0];
            document.getElementById('purchaseDate').value = today;

            // 添加表单提交动画
            const form = document.querySelector('form');
            const submitBtn = document.querySelector('.btn-primary');

            form.addEventListener('submit', function() {
                submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 保存中...';
                submitBtn.disabled = true;
            });
        });
    </script>
</body>
</html> 